use dta\DataPrep.dta, clear 

keep if running==1 & running_prev1==1
gen rankchange=rank-rank_prev1 if rank_prev1!=99
gen rankimprove=0
replace rankimprove=1 if rankchange<0

**** POOL RANK 5 AND LOWER: 
replace rank=5 if rank>5

forvalues i=2(1)5{
		preserve 
		keep if rank_prev1==`i'
		collapse rankimprove, by(female year)
		tw (scatter rankimprove year if female==0, connect(l) lpattern(solid) msymbol(S) mcolor(gray) mlcolor(gray)) /// 
		(scatter rankimprove year if female==1, connect(l) lpattern(solid) msymbol(O) mcolor(black) mlcolor(black)), ///
		title(Rank `i' at t-1) graphregion(color(white) ) legend(order(1 "Men" 2 "Women") col(2) region(lstyle(none))) ///
		ytitle(Better rank at t) ylabel(,angle(0)) scheme(s2mono) xlabel(1949(4)2021, angle(45) labsize(small)) 
		graph save figures/gph/rankimprove_`i'.gph, replace
		restore
		}
		
cd figures/gph/
grc1leg rankimprove_2.gph rankimprove_3.gph rankimprove_4.gph rankimprove_5.gph, ycommon graphregion(color(white) ) scheme(s1mono)
graph play 5PLUS /* manually edit the lower right panel title "rank 5" to "rank 5+" */
graph export ../FigureA8.pdf, replace
cd ../../